package com.shangguosha.model;

import com.shangguosha.core.GameObject;
import com.shangguosha.model.enums.SkillType;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 技能抽象基类
 */
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class Skill extends GameObject {
    protected SkillType skillType;
    protected String description;
    protected Character owner;
    protected boolean isActive;
    protected int usageCount;
    protected int maxUsagePerTurn;
    
    public Skill(String id, String name, SkillType skillType, String description) {
        super(id, name);
        this.skillType = skillType;
        this.description = description;
        this.isActive = false;
        this.usageCount = 0;
        this.maxUsagePerTurn = -1; // -1表示无限制
    }
    
    public Skill(String id, String name, SkillType skillType, String description, int maxUsagePerTurn) {
        super(id, name);
        this.skillType = skillType;
        this.description = description;
        this.isActive = false;
        this.usageCount = 0;
        this.maxUsagePerTurn = maxUsagePerTurn;
    }
    
    /**
     * 检查技能是否可以使用
     */
    public abstract boolean canUse(Character user, Object... params);
    
    /**
     * 使用技能
     */
    public abstract void use(Character user, Object... params);
    
    /**
     * 获取技能效果描述
     */
    public abstract String getEffectDescription();
    
    // 触发相关方法
    public boolean canTrigger(String eventType, Object eventData) {
        return isActive && canUse(owner, eventData);
    }
    
    public void trigger(String eventType, Object eventData) {
        if (canTrigger(eventType, eventData)) {
            use(owner, eventData);
            usageCount++;
        }
    }
    
    // 使用次数管理
    public void resetUsage() {
        this.usageCount = 0;
    }
    
    public boolean canUseThisTurn() {
        return maxUsagePerTurn == -1 || usageCount < maxUsagePerTurn;
    }
    
    // 激活/停用
    public void activate() {
        this.isActive = true;
    }
    
    public void deactivate() {
        this.isActive = false;
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
        // 技能创建时的初始化逻辑
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        this.isActive = false;
    }
    
    @Override
    public String toString() {
        return String.format("%s[%s] - %s", getName(), skillType, description);
    }
}